package com.example.day02.service.impl;

import com.example.day02.dao.UserDao;
import com.example.day02.pojo.User;
import com.example.day02.service.UserService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public String add(User user) {
        if (user==null){
            return "参数为空";
        }
        if (user.getName()==null){
            return "姓名为空";
        }
        log.info("参数user:{}",user);
        user.setCtime(new Date());
        userDao.add(user);
        return "成功";
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public String edit(User user) {
        log.info("参数user:{}",user);
        user.setCtime(new Date());
        userDao.edit(user);
        return "成功";
    }

    @Override
    public String delete(Integer id) {
        userDao.delete(id);
        return "成功";
    }
}
